package com.wyb.controller;

import com.wyb.mapper.ArticleMapper;
import com.wyb.pojo.Article;
import com.wyb.constant.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/articles")
@PreAuthorize("hasAnyAuthority('sys:cm:list')")
public class TopArticleController {

    @Autowired
    private ArticleMapper articleMapper;
    @PostMapping("/settop")
    public Result setTop(@RequestBody Article article){

        return articleMapper.updateById(article)!=0 ? new Result(200, "文章成功置顶", null)
                                                    : new Result(201, "文章置顶失败", null);
    }
    @PostMapping("/canceltop")
    public Result cancelTop(@RequestBody Article article){

        return articleMapper.updateById(article)!=0 ? new Result(200, "文章成功取消置顶", null)
                                                    : new Result(201, "文章取消置顶失败", null);
    }

}
